﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class HomePage_CompanyList : System.Web.UI.Page
{
    public string strConditions,strAreaName,strAreaId;

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            strAreaName = Request.Form["AreaName"];
            strAreaId = Request.Form["AreaId"];
            if (!IsPostBack)
            {
                //Db DbProject = new Db();
                //string strSql = "SELECT AccountId,AccountName FROM ACCOUNT WHERE TYPE=0 OR TYPE=1 OR  TYPE=6 ";
                //System.Data.IDataReader dr = DbProject.DataReader(strSql);
                //lstSHR.DataSource = dr;
                //lstSHR.Items.Add("全部");
                //while (dr.Read())
                //{
                //    lstSHR.Items.Add(dr["AccountName"].ToString());
                //}
                //dr.Close();
                //dr.Dispose();
                //DbProject.Close();
                lstQYType.Items.Add("全部");
                lstQYType.Items.Add("经营企业");
                lstQYType.Items.Add("生产企业");
                //lstCheckStatus.Items.Add("全部");
                //lstCheckStatus.Items.Add("未审核");
                //lstCheckStatus.Items.Add("审核通过");
                //lstCheckStatus.Items.Add("审核未通过");
                //lstMemo2.Items.Add("全部");
                //lstMemo2.Items.Add("已保存未提交");
                //lstMemo2.Items.Add("已提交");

            }
            showGridView();
        }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    public void showGridView()
    {
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_company";                                               //要查询的表明
        dbPage.Key = "accountid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "accountid,CompanyName,UserCode";//,case when  CheckStatus is null then '未审核' when  CheckStatus='0' then '未审核' when  CheckStatus='1' then '审核通过' when  CheckStatus='2'then '审核不通过'  end CheckStatus, AccountName_SHR ,AccountName_TJR ,memo6 ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 24;                                                    //没有显示记录条数   
        dbPage.OrderBy = "CompanyName,UserCode";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlAttorney.DataSource = dr;
        DlAttorney.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", CompanyName = "", _UserCode, QYType;//, CheckStatus, _AccountName_SHR, Memo2;
        QYType = lstQYType.SelectedValue.ToString().Trim();
        switch (QYType)
        {
            case "全部":
                break;
            case "经营企业":
                strtemp = " Sort=1 and";
                break;
            case "生产企业":
                strtemp = " Sort=0 and";
                break;
        }
        //_AccountName_SHR = lstSHR.SelectedValue;

        //Memo2 = lstMemo2.SelectedValue;
        //switch (Memo2)
        //{
        //    case "全部":
        //        break;
        //    case "已保存未提交":
        //        strtemp = strtemp + " memo2=0 and";
        //        break;
        //    case "已提交":
        //        strtemp = strtemp + " memo2=1 and";
        //        break;
        //}
        //CheckStatus = lstCheckStatus.SelectedValue.ToString();
        //switch (CheckStatus)
        //{
        //    case "全部":
        //        break;
        //    case "未审核":
        //        strtemp = strtemp + " (CheckStatus=0 or CheckStatus is null) and";
        //        break;
        //    case "审核通过":
        //        strtemp = strtemp + " CheckStatus=1 and";
        //        break;
        //    case "审核未通过":
        //        strtemp = strtemp + " CheckStatus=2 and";
        //        break;
        //}
        CompanyName = txtAttorneyName.Text.ToString();
        _UserCode = txtUserCode.Text.ToString().Trim();
        //if (_AccountName_SHR != "全部")
        //{
        //    strtemp = strtemp + " AccountName_SHR like '%" + _AccountName_SHR + "%' and";
        //}
        if (strAreaId != null && strAreaId != "")
        {
            strtemp = strtemp + " AreaId =" + strAreaId + " and";
        }
        if (_UserCode != "")
        {
            strtemp = strtemp + " UserCode like '%" + _UserCode + "%' and";
        }
        if (CompanyName != "")
        {
            strtemp = strtemp + " CompanyName like '%" + CompanyName + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;
    }

}
